<?php

/**
 * Exemples Hoathis_Convertor
 *
 * @author      Gregory DARCHE <tetardo@gmail.com>
 * @copyright   Copyright (c) 2009 Gregory DARCHE.
 * @license     http://gnu.org/licenses/gpl.txt GNU GPL
 * @since       PHP 5
 * @package     Hoathis_Convertor
 */

error_reporting(E_ALL);

set_include_path('./'            		 . PATH_SEPARATOR .
                 './../Application' 	 . PATH_SEPARATOR .
                 './../Framework/Core/'  . PATH_SEPARATOR .
                 get_include_path());

require_once 'Framework.php';

importModule('Convertor.~');

importModule('Convertor.Format.Currency');
importModule('Convertor.Format.Translation');
importModule('Convertor.Format.Metric');
importModule('Convertor.Format.Octet');
importModule('Convertor.Format.Liquid');
importModule('Convertor.Format.Accent');
importModule('Convertor.Format.Radio');
importModule('Convertor.Format.Morse');
importModule('Convertor.Format.Mass');
importModule('Convertor.Format.Force');
importModule('Convertor.Format.Pressure');
importModule('Convertor.Format.Speed');
importModule('Convertor.Format.Volum');
importModule('Convertor.Format.Iphost');
importModule('Convertor.Format.Strbin');

importModule('Convertor.Filter.Number');
importModule('Convertor.Filter.Pourcent');
importModule('Convertor.Filter.Round');
importModule('Convertor.Filter.Unit');
importModule('Convertor.Filter.Censure');

/**
 * Translation
 */
echo Hoathis_Convertor::getInstance('Translation', 'C\'est l\'anniversaire de danny.', 'fr', 'en').'<br />';
echo Hoathis_Convertor::getInstance('Translation', 'Bob est un gentil chien.', 'fr', 'es')->addFilter('Censure', array(
    'list' => 'greg, danny',
    'remplace' => '**************'
)).'<br />';

/**
 * Currency
 */
echo Hoathis_Convertor::getInstance('currency', 10, 'USD', 'EUR').'<br />';

// with simple filter
echo Hoathis_Convertor::getInstance('currency', 525.503, 'EUR', 'USD')->addFilter('Unit', array(
    'unit' => 'USD $',
    'location' => 'before' // before | after
)).'<br />';

/**
 * Metric
 */
echo Hoathis_Convertor::getInstance('metric', 5000, 'm', 'km').'<br />';
echo Hoathis_Convertor::getInstance('METRIC', 25, 'cm', 'm').'<br />';

// with simple filter
$c = Hoathis_Convertor::getInstance('Metric', 525.503, 'm', 'cm');
$c->addFilter('Number', array(
    'separator' => ',',
    'thousandSeparator' => '`'
));
$c->addFilter('Unit', array(
    'unit' => 'cm',
    'location' => 'after' // before | after
));
echo $c.'<br />';

echo Hoathis_Convertor::getInstance('metric', 100, 'm')->addFilter('Pourcent', array(
'value' => 50,
'mode' => '+'
));

// with many filters
echo Hoathis_Convertor::getInstance('metric', 525.5034251, 'm', 'cm')->addFilters(array(
    'Round' => array(
        'precision' => 2,
        'mode' => 'auto'
    ),
    'Number' => array(
        'separator' => ',',
        'thousandSeparator' => ' '
    ),
    'Unit' => array(
        'unit' => 'cm',
        'location' => 'after' // before | after
    )
)).'<br />';

// no convertion with just many filters
echo Hoathis_Convertor::getInstance('metric', 250.247457881265, 'm'/*, 'cm'*/)->addFilters(array(
    'Round' => array(
        'precision' => 2,
        'mode' => 'auto'
    ),
    'Number' => array(
        'separator' => ',',
        'thousandSeparator' => ' '
    ),
    'Unit' => array(
        'unit' => 'cm',
        'location' => 'after' // before | after
    )
)).'<br />';

/**
 * Octet
 */
echo Hoathis_Convertor::getInstance('octet', 300, 'Mo', 'Go').'<br />';
echo Hoathis_Convertor::getInstance('octet', 250.247, 'Mo', 'Ko').'<br />';

/**
 * Liquid
 */
echo Hoathis_Convertor::getInstance('liQUiD', 300, 'mL', 'dL').'<br />';
echo Hoathis_Convertor::getInstance('liquid', 250.247, 'mL', 'L').'<br />';

/**
 * Accent
 */
echo Hoathis_Convertor::getInstance('accent', 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'accent', 'noaccent').'<br />';

/**
 * Radio
 */
echo Hoathis_Convertor::getInstance('radio',
    'HOTEL OSCAR ALPHA | FOXTROT romeo alpha mike echo whisky oscar romeo kilo Stop |
     CHARLIE oscar delta echo | romeo alpha delta india oscar Stop',
    'radio', 'txt').'<br />';
echo Hoathis_Convertor::getInstance('radio', 'HOA Framework. Code radio.', 'txt', 'radio').'<br />';

/**
 * Morse
 */
echo Hoathis_Convertor::getInstance('morse', '.... --- .- | ..-.. .-. .- -- . .-- --- .-. -.- .-.-.-
    | -.-. --- -.. . | -- --- .-. ... . .-.-.-',
'morse', 'txt').'<br />';
echo Hoathis_Convertor::getInstance('morse', 'HOA Framework. Code morse.', 'txt', 'morse').'<br />';

/**
 * Mass
 */
echo Hoathis_Convertor::getInstance('mass', 300, 'g', 'kg').'<br />';
echo Hoathis_Convertor::getInstance('mass', 250.247, 'kg', 'g').'<br />';

/**
 * Force
 */
echo Hoathis_Convertor::getInstance('force', 300, 'N', 'mN').'<br />';
echo Hoathis_Convertor::getInstance('force', 250.247, 'mN', 'N').'<br />';

/**
 * Pressure
 */
echo Hoathis_Convertor::getInstance('pressure', 300, 'hP', 'kP').'<br />';
echo Hoathis_Convertor::getInstance('pressure', 250.247, 'aPhy', 'aTech').'<br />';
echo Hoathis_Convertor::getInstance('pressure', 300, 'cmE', 'pE').'<br />';
echo Hoathis_Convertor::getInstance('pressure', 250.247, 'cM', 'mmM').'<br />';

/**
 * Speed
 */
echo Hoathis_Convertor::getInstance('speed', 60, 'kmS', 'mileS').'<br />';
echo Hoathis_Convertor::getInstance('speed', 15, 'kmH', 'mileH').'<br />';

/**
 * Volum
 */
echo Hoathis_Convertor::getInstance('volum', 60, 'm3', 'mm3').'<br />';
echo Hoathis_Convertor::getInstance('volum', 15, 'cm3', 'mm3').'<br />';

/**
 * Iphost
 */
echo Hoathis_Convertor::getInstance('iphost', 'www.google.fr', 'hostname', 'ip').'<br />';
echo Hoathis_Convertor::getInstance('iphost', '74.125.79.103', 'ip', 'hostname').'<br />';

/**
 * Strbin
 */
echo Hoathis_Convertor::getInstance('strbin', '01000001 01000010 01000011', 'binary', 'string').'<br />';
echo Hoathis_Convertor::getInstance('strbin', 'ABC', 'string', 'binary').'<br />';

/**
 * Just use filters
 */
$param = array(
    'list' => 'enfoiré  ,idiot       ,bla    ,   bla',
    'remplace' => '***** Ce texte a été censuré pour non respect des conditions d\'utilisation *****'
);
echo new Hoathis_Convertor_Filter_Censure('C\'est vraiment un idiot cet hamster !', $param).'<br />';